<template>
    <view class="content">
        <view class="bg"></view>
        <view class="top-img">
            <image src="../static/image/r1.png" class="r-img"></image>
            <!-- <image src="../static/image/r2.png" class="r-img"></image> -->
            <!-- <image src="../static/image/r3.png" class="r-img"></image> -->
        </view>
        
        <view class="box">
            <view class="title">身份证</view>
            <view class="img-box">
                <view class="img">
					<view class="u-rela" v-if="front">
					    <image :src="front" class="s-up" @click="$previewImageSA(front)"></image>
					    <view class="del-img" @click.stop="delImage(1)">删除</view>
					</view>
					<image src="../static/image/s_up1.png" class="s-up" v-else @click="chooseImage(1)"></image>
					
                    <view class="tip">请上传身份证正面</view>
                </view>
                <view class="img">
					<view class="u-rela" v-if="back">
					    <image :src="back" class="s-up" @click="$previewImageSA(back)"></image>
					    <view class="del-img" @click.stop="delImage(2)">删除</view>
					</view>
					<image src="../static/image/s_up2.png" class="s-up" v-else @click="chooseImage(2)"></image>
					
                    <view class="tip">请上传身份证背面</view>
                </view>
            </view>
            
            <view class="title">行驶证</view>
            <view class="img-box">
                <view class="img">
					<view class="u-rela" v-if="travel_front">
					    <image :src="travel_front" class="s-up" @click="$previewImageSA(travel_front)"></image>
					    <view class="del-img" @click.stop="delImage(3)">删除</view>
					</view>
					<image src="../static/image/s_up3.png" class="s-up" v-else @click="chooseImage(3)"></image>
					
                    <view class="tip">请上传行驶证正面</view>
                </view>
                <view class="img">
					<view class="u-rela" v-if="travel_back">
					    <image :src="travel_back" class="s-up" @click="$previewImageSA(travel_back)"></image>
					    <view class="del-img" @click.stop="delImage(4)">删除</view>
					</view>
					<image src="../static/image/s_up3.png" class="s-up" v-else @click="chooseImage(4)"></image>
					
                    <view class="tip">请上传行驶证背面</view>
                </view>
            </view>
            
            <view class="title">驾驶证</view>
            <view class="img-box">
                <view class="img">
					<view class="u-rela" v-if="drive">
					    <image :src="drive" class="s-up" @click="$previewImageSA(drive)"></image>
					    <view class="del-img" @click.stop="delImage(5)">删除</view>
					</view>
					<image src="../static/image/s_up3.png" class="s-up" v-else @click="chooseImage(5)"></image>
					
                    <view class="tip">请上传驾驶证</view>
                </view>
            </view>
            
            <view class="title">车辆外观</view>
            <view class="img-box">
                <view class="img">
					<view class="u-rela" v-if="appearance">
					    <image :src="appearance" class="s-up" @click="$previewImageSA(appearance)"></image>
					    <view class="del-img" @click.stop="delImage(6)">删除</view>
					</view>
					<image src="../static/image/s_up3.png" class="s-up" v-else @click="chooseImage(6)"></image>
					
                    <view class="tip">请上传车辆外观</view>
                </view>
            </view>
        </view>
		
		<view class="box" v-if="info&&info.status == 3">
			<view class="title">审核失败原因</view>
			<view class="u-p-b-20">{{info.reason}}</view>
		</view>
        
        <view class="btn" @click="$noMultipleClicks(next)">下一步</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                noClick: true,//连点
				info: {},
				front_id: '',//身份证正面id
				front: '',
				back_id: '',//身份证背面id
				back: '',
				travel_front_id: '',//行驶证正面图片id
				travel_front: '',
				travel_back_id: '',//行驶证背面图片id
				travel_back: '',
				drive_id: '',//驾驶证图片id
				drive: '',
				appearance_id: '',//车辆外观图片id
				appearance: '',
            };
        },
		onLoad() {
			if (uni.getStorageSync('userToken')) {
				this.getInfo()
			}
			
			uni.$on('LOGIN', data => {
				this.getInfo()
			})
		},
        onShow() {
            if (!uni.getStorageSync('userToken')) {
                this.$confirm('请先登录并且绑定手机号，是否去登录？',()=>{
                    uni.navigateTo({
                        url: `/pagesA/login/login?user_type=2`
                    })
                })
            } else if (!uni.getStorageSync('MOBILE')) {
                this.$confirm('您还没有绑定手机号，是否去绑定？',()=>{
                    uni.navigateTo({
                        url: `/pagesA/login/login?show=1&user_type=2`
                    })
                })
            }
        },
        methods: {
			delImage(num) {
				uni.showModal({
				    title: '温馨提示',
				    content: '确定要删除照片吗？',
				    success: res => {
				        if (res.confirm) {
							if (num == 1) {
								this.front = ''
								this.front_id = ''
							} else if (num == 2) {
								this.back = ''
								this.back_id = ''
							} else if (num == 3) {
								this.travel_front_id = ''
								this.travel_front = ''
							} else if (num == 4) {
								this.travel_back_id = ''
								this.travel_back = ''
							} else if (num == 5) {
								this.drive_id = ''
								this.drive = ''
							} else if (num == 6) {
								this.appearance_id = ''
								this.appearance = ''
							}
							
				        } else if (res.cancel) {
				            
				        }
				    }
				});
			},
			
            // 下一步
            next() {
				if (!this.front_id) {
					this.$toast('请上传身份证正面')
					return
				}
				if (!this.back_id) {
					this.$toast('请上传身份证背面')
					return
				}
				if (!this.travel_front_id) {
					this.$toast('请上传行驶证正面')
					return
				}
				if (!this.travel_back_id) {
					this.$toast('请上传行驶证背面')
					return
				}
				if (!this.drive_id) {
					this.$toast('请上传驾驶证')
					return
				}
				if (!this.appearance_id) {
					this.$toast('请上传车辆外观')
					return
				}
				
				let data = {
					front_id: this.front_id,
					back_id: this.back_id,
					travel_front_id: this.travel_front_id,
					travel_back_id: this.travel_back_id,
					drive_id: this.drive_id,
					appearance_id: this.appearance_id
				}
				const newData = JSON.stringify(data)
                this.$cTo(`/pagesA/apply/apply-2?data=${encodeURIComponent(newData)}`)
            },
			
			getInfo() {
			    this.$ajax('driver_detail', {
			        user_token: this.$getSync('userToken'),
			    }).then(ret => {
			        if (ret.success == 1000) {
						this.info = ret.detail
						if (this.info && this.info.status == 2 || this.info.status == 3) {
							this.front_id = this.info.front_id
							this.front = this.info.front_img
							this.back_id = this.info.back_id
							this.back = this.info.back_img
							this.travel_front_id = this.info.travel_front_id
							this.travel_front = this.info.travel_front_img
							this.travel_back_id = this.info.travel_back_id
							this.travel_back = this.info.travel_back_img
							this.drive_id = this.info.drive_id
							this.drive = this.info.drive_img
							this.appearance_id = this.info.appearance_id
							this.appearance = this.info.appearance_img
						}
			        } else {
			            this.$toast(ret.msg);
			        }
			    });
			},
			
			chooseImage(num) {
				if (this.info.status != 1) {
					uni.chooseImage({
					    count: 1, //默认9
					    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					    sourceType: ['album', 'camera'], // 相机拍照 album 相册、camera 拍照
					    success: (res) => {
					        this.$upLoadPic(res.tempFilePaths[0]).then(ret => {
					            console.log(ret)
								let data = ret.detail
								if (num == 1) {
									this.front_id = data.image_id//身份证正面
									this.front = data.image
								} else if (num == 2) {
									this.back_id = data.image_id//身份证背面
									this.back = data.image
								} else if (num == 3) {
									this.travel_front_id = data.image_id//行驶证正面
									this.travel_front = data.image
								} else if (num == 4) {
									this.travel_back_id = data.image_id//行驶证背面
									this.travel_back = data.image
								} else if (num == 5) {
									this.drive_id = data.image_id//驾驶证
									this.drive = data.image
								} else if (num == 6) {
									this.appearance_id = data.image_id//车辆外观
									this.appearance = data.image
								}
					        });
					    }
					});
				}
			},
        }
    };
</script>

<style lang="scss">
	.img-box-cen{
	    display: flex;
	    flex-wrap: wrap;
	    justify-content: flex-start;
	    align-items: center;
	}
	.del-img{
	    position: absolute;
	    right: 0;
	    bottom: 0;
	    color: #FFFFFF;
	    font-size: 22rpx;
	    padding: 7rpx 12rpx;
	    background-color: #000000;
	    opacity: .7;
	    border-radius: 5rpx;
	}
    
    page{
        background-color: #f2f4fa;
    }
    .content {
    	padding: 30rpx 20rpx;
    }
    .bg {
    	width: 100%;
    	height: 600rpx;
    	position: absolute;
    	top: 0;
    	left: 0;
    	z-index: -1;
        background: linear-gradient(to bottom, #004580,#18568c, #f2f4fa);
    }
    .top-img{
        padding: 10rpx 0 40rpx;
    }
    .r-img{
        width: 538rpx;
        height: 70rpx;
        margin: auto;
    }
    
    .box{
        padding: 30rpx 30rpx 0;
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
    }
    .title{
        font-size: 34rpx;
        font-weight: bold;
        padding-bottom: 20rpx;
    }
    .img-box{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 55rpx;
    }
    .img{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    .s-up{
        width: 305rpx;
        height: 193rpx;
    }
    .tip{
        font-size: 24rpx;
        color: #a4a4a4;
        padding-top: 25rpx;
    }
    .btn{
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        padding: 25rpx;
        background-color: #00457f;
        border-radius: 50rpx;
        margin-top: 50rpx;
    }

</style>
